const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    plugin_name:"",
    avatar:"",
    level_name:"",
    area_level_name:"",
    nickname:"",
    active: 'index',
    tabs: [],
    order:0.00,
    show_tabs:false,

    area_list:[],
    area_total_page:1,
    area_page:1,
    area_sum:"",
    info:{},
  
    list:[],
    sum: '',
    total_page: 1,
    page: 1,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function () {
    let language = wx.getStorageSync("langIndex");
    this.setData({
      language: language.en,
    });
    this.get_weekly();

  },
  onChange({detail:{name}}) {
    this.setData({active:name})
    if(name == 'index'){
      this.get_weekly();
    }else{
      this.get_area()
    }
  },
  goto(){
    let num = this.data.active=='index'?1:2;
    wx.navigateTo({
      url: '/packageI/sino_skill/order/order?num='+num,
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },
  
  get_area(page = 1) {
    app._postNetWork({
      url:app.getNetAddresss("plugin.weekly-rewards.frontend.controllers.center.area"),
      data:{page},
      success:resdata=>{
        let {result,data,msg,level_name }= resdata.data;
        if(result){
          let area_list = [];
          let {info,sum,list,order} = data;
          if(list.data && list.data.length!==0){
            (page == 1)?(area_list = list.data):(area_list = this.data.area_list.concat(list.data));
            this.setData({
              area_level_name:level_name,
              order,
              area_list,
              area_sum:sum,
              area_total_page:list.last_page,
              area_page:list.current_page,
            })
          }
          this.setData({show_tabs:true,avatar:info?.info,nickname:info?.nickname,info})
        }else{
          this.setData({show_tabs:false})
          app.tips(msg);
        }
      }
    })
  },
   get_weekly(page = 1) {
    app._postNetWork({
      url:app.getNetAddresss("plugin.weekly-rewards.frontend.controllers.center.index"),
      data:{page},
      success:async resdata=>{
        let {result,data,msg,level_name} = resdata.data;
        if(result){
          let {info,sum,list,order,plugin_name} = data;
          wx.setNavigationBarTitle({
            title: plugin_name,
          })
          console.log(data,"data===");
          this.setData({plugin_name})
          let _list = [];
          if(list.data && list.data.length!==0){
            (page == 1)?(_list = list.data || []):(_list = this.data.list.concat(list.data));
            this.setData({
              level_name,
              list:_list,
              order,
              sum,
              total_page:list.last_page,
              page:list.current_page,
            })
          }
        
          this.setData({avatar:info?.avatar,nickname:info?.nickname,info})
        }else{
          app.tips(msg);
        }
   
      }
    })
      
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if(this.data.active == 'index'){
      if(this.data.page>=this.data.total_page){
        return false;
      }
      let page = this.data.page + 1;
      this.get_weekly(page)
    }else{
      if(this.data.area_page>=this.data.area_total_page){
        return false;
      }
      let page = this.data.area_page + 1;
      this.get_area(page)

    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})